<?php
include_once "../header1.php";
?>
<link rel="stylesheet" href="../css/datepicker.css" type="text/css" />
    <link rel="stylesheet" media="screen" type="text/css" href="../css/layout.css" />
  	<script type="text/javascript" src="../js/jquery.js"></script>
	<script type="text/javascript" src="../js/datepicker.js"></script>
    <script type="text/javascript" src="../js/eye.js"></script>
    <script type="text/javascript" src="../js/utils.js"></script>
    <script type="text/javascript" src="../js/layout.js?ver=1.0.2"></script>
    </head>
<body>
<?php
include_once ("../Login/databaseconnection.php");

if(!loggedin())
{
	require_once ("../index.php");
}
 else
   {
   date_default_timezone_set("Europe/Paris");
   $t_d=date("Y-m-d");
	if(isset($_POST['Register']))
{
    $Training_Id=$_POST['Training_Id'];
	 $T_NIC_Number=$_POST['T_NIC_Number'];
     $Member_Id=$_POST['Member_Id'];
    $From_Date=$_POST['From_Date'];
	if($Training_Id==""||$T_NIC_Number=="Select One")
	   {
	   	    $_SESSION['errorin']="All details are required Please fill all!";
	   }
if($Training_Id!=""&&$T_NIC_Number!="Select One")
	   {
$ReTE_Che=mysql_query("SELECT * FROM resource_team WHERE T_NIC_Number='$T_NIC_Number' AND T_NIC_Number='$T_NIC_Number'");
if($rowrete=mysql_fetch_array($ReTE_Che))
		{
			$_SESSION['errorexi']="Sorry this Member's record already exists";
		}
		
		else
		{
		if($_SESSION['Access_Type']=="Teacher in Charge")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $getthsch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'"); 
   if($roSch=mysql_fetch_array($getthsch))
   {
$Sch_Id=$roSch['School_Id'];   
   if($Sch_Id==$Own_School_Id)
	{
		require_once 'insertrest.php';
		}
		 else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
		}
		else
	   {
	   $_SESSION['errornotallo']="This person's record is not registered into Teacher's record!";
	   }
		}
		}
		else if($_SESSION['Access_Type']=="Administrator")
{
require_once 'insertrest.php';
}   
   else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
	}
	}
	}
?>
 <?php
include_once "../header2.php";
?>
<?php
include_once "topmenu.php";
?>
<div id="content">
	<div id="main">
	  <div id="bodyfield">
<div id="lefttablereg">
<form action="#" method="POST">
<br/>
<table>
<tr>
<td width="502" height="21" class="err">
<?php
if(isset($_POST['Register']))
{
	if(isset($_SESSION['errorin']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorin'];
		unset($_SESSION['errorin']);
	}
	if(isset($_SESSION['error']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['error'];
		unset($_SESSION['error']);
		
	}
	if(isset($_SESSION['errorexi']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorexi'];
		unset($_SESSION['errorexi']);
		
	}
}
?></td>
</tr>
</table>
   <table width="528" border="0" class="tablefontv">
     <tr>
       <td width="42">&nbsp;</td>
       <td width="42"><font color="red" size="+2"><p align="center">*</p></font></td>
       <td width="142" height="32">Teachers NIC Number </td>
       <td>:-</td>
	   
       <td width="42">
	   <form action="#" method="post" name="form">
	   <select name="T_NIC_Number" onChange="javascript:this.form.submit()">
      <?php
	  $T_NIC_Num=$_POST['T_NIC_Number'];
	  if(isset($T_NIC_Num))
	  {
	  $tra_tea=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='".$T_NIC_Num."'");
	 if($row_tea=mysql_fetch_array($tra_tea))
	 {
	 $Teacher_Name=$row_tea['First_Name']." ".$row_tea['Last_Name']."(".$T_NIC_Num.")";
	 }
	  echo '<option value="'.$T_NIC_Num.'">'.$Teacher_Name.'</option>';
	  }
	  if(isset($_POST['Register']))
	  {
	  $tra_tea=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='".$T_NIC_Number."'");
	 if($row_tea=mysql_fetch_array($tra_tea))
	 {
	 $Teacher_Name=$row_tea['First_Name']." ".$row_tea['Last_Name']."(".$T_NIC_Number.")";
	 }
	 echo '<option value="'.$T_NIC_Number.'">'.$Teacher_Name.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
      <?php
	  $scho=mysql_query("SELECT DISTINCT(T_NIC_Number) FROM teacher");
	 while($row=mysql_fetch_array($scho))
  {
	  $nicnum=$row['T_NIC_Number'];
	  $tra_tea=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='".$nicnum."'");
	 if($row_tea=mysql_fetch_array($tra_tea))
	 {
	 $Teacher_Name=$row_tea['First_Name']." ".$row_tea['Last_Name']."(".$nicnum.")";
	 }
if($T_NIC_Number!=$nicnum)
{
	  echo '<option value="'.$nicnum.'">'.$Teacher_Name.'</option>';
}
  }
	  ?>
    </select>
	</form></td>
     </tr>
     <tr>
       <td>&nbsp;</td>
       <td><font color="red" size="+2"><p align="center">*</p></font></td>
       <td height="32">Training Id </td>
       <td>:-</td><td>
	   <select name="Training_Id" id="select">
        <?php
	  
	  if(isset($_POST['Register']))
	  {
	  $tra_pro=mysql_query("SELECT * FROM training WHERE Training_Id='".$Training_Id."'");
	 if($row_tra=mysql_fetch_array($tra_pro))
	 {
	 $Training_name=$row_tra['Training_Name'];
	 }
	 echo '<option value="'.$Training_Id.'">'.$Training_name.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
	  $com=mysql_query("SELECT DISTINCT(Training_Id) FROM training");
	  
  while($row=mysql_fetch_array($com))
  {
	 $Tra_Id=$row['Training_Id'];
	 $tra_pro=mysql_query("SELECT * FROM training WHERE Training_Id='".$Tra_Id."'");
	 if($row_tra=mysql_fetch_array($tra_pro))
	 {
	 $Tra_name=$row_tra['Training_Name'];
	 }
if($Tra_Id!=$Training_Id)
{
	  echo '<option value="'.$Tra_Id.'">'.$Tra_name.'</option>';
}
  }
 
	  ?>
      </select><br/><label><font color="red">or</font> New training programme:</label>&nbsp;&nbsp;&nbsp;
	  <?php
	  if($New_Training!="")
	  {
	  echo "<input type='text' name='New_Training' value='$New_Training'/>";
	  }
	  else
	  {
	  echo "<input type='text' name='New_Training'/>";
	  }
	  ?></td>	 
       <td></td>
     </tr>
     <tr>
       <td>&nbsp;</td>
       <td><font color="red" size="+2"><p align="center">*</p></font></td>
       <td height="32">Member Id </td>
       <td>:-</td>
	   <?php
	   if(isset($_POST['Register']))
{
echo '<td>';
echo "<input type='text' name='Member_Id' value='$Member_Id'/>";
echo '</td>';

}
else
{
echo '<td>';
$T_NIC_Num=$_POST['T_NIC_Number'];
if($T_NIC_Num=="Select One")
{
echo "<input type='text' name='Member_Id'/>";
}
else
{
$getmid=mysql_query("SELECT * FROM resource_team WHERE T_NIC_Number='$T_NIC_Num'");
if($rowmid=mysql_fetch_array($getmid))
{
$mid=$rowmid['Member_Id'];
if(isset($mid))
{
echo "<input type='text' name='Member_Id' value='$mid'/>";
}
}
else
{
echo "<input type='text' name='Member_Id' value='M0001'/>";
}
}
}
echo '</td>';
?>
       <td></td>
     </tr>
     <tr>
     <td>&nbsp;</td>
       <td><font color="red" size="+2"><p align="center">*</p></font></td>
       <td height="32">From Date </td>
       <td>:-</td>
	   <?php
	   if(isset($_POST['Register']))
{

echo '<td>';
echo "<input type='text' name='From_Date' value='$From_Date' class='inputDate' id='inputDate'>";
echo '</td>';
}
else
{
echo '<td>';
echo "<input type='text' name='From_Date' value='$t_d' class='inputDate' id='inputDate'>";
echo '</td>';

}?>
       <td></td>
     </tr>
     <tr>
       <td></td>
       <td colspan="3"><a href="insert.php" class="reset">Reset | </a><input type="submit" value="Register" name="Register" class="buttonok"/>
      </td>
       </tr>
   </table>
</form>
 </div>
 <div id="righttablereg">
 <?php
		if(isset($_POST['Register']))
{
	if($_SESSION['OK']=="OK")
	{
	if($_SESSION['Access_Type']=="Teacher in Charge")
	{
		$NIC_Number=$_SESSION['NIC_Number'];
		$result=mysql_query("SELECT * FROM resource_team WHERE T_NIC_Number='$NIC_Number'");
		echo '<br/>';
		if(mysql_num_rows($result)!=0)
		{
			echo '<table width="500" border="1" class="tablefontv" >
			<tr bgcolor="#6AB5FF">
			<td width="100"><b>Training Id</b></td>
			<td width="100"><b>Member Id</b></td>
			<td width="100"><b>Teachers NIC Number</b></td>
			<td width="130"><b>From Date</b></td>
			<td width="130"><b>Last_Updated_Date</b></td>
			</tr>';
					while($row=mysql_fetch_array($result))
					{
						$Training_Id=$_SESSION['Training_Id'];
						$T_NIC_Number=$_SESSION['T_NIC_Number'];
						if($row['Training_Id']==$Training_Id&&$row['T_NIC_Number']==$T_NIC_Number)
						{
							echo '<tr bgcolor="#936">';
							echo '<td width="100">'.$row['Training_Id'].'</td>';
							echo '<td width="100">'. $row['Member_Id'].'</td>';
							echo '<td width="100">'.$row['T_NIC_Number'].'</td>';
							echo '<td width="100">'.$row['From_Date'].'</td>';
							echo '<td width="130">'.$row['Last_Updated_Date'].'</td>';
							echo '</tr>';
							unset($_SESSION['Training_Id']);
							unset($_SESSION['T_NIC_Number']);
						}
						else
						{
							echo '<tr bgcolor="#CCCCCC">';
							echo '<td width="100">'.$row['Training_Id'].'</td>';
							echo '<td width="100">'. $row['Member_Id'].'</td>';
							echo '<td width="100">'.$row['T_NIC_Number'].'</td>';
							echo '<td width="100">'.$row['From_Date'].'</td>';
							echo '<td width="130">'.$row['Last_Updated_Date'].'</td>';
							echo '</tr>';
						}
					}
					echo "</table>";
			}
		}
	if($_SESSION['Access_Type']=="Administrator")
	{
		$result=mysql_query("SELECT * FROM resource_team");
		echo '<br/>';
		if(mysql_num_rows($result)!=0)
		{
					echo '<table width="500" border="1" class="tablefontv" >
					<tr bgcolor="#6AB5FF">
					<td width="100"><b>Training Id</b></td>
					<td width="100"><b>Member Id</b></td>
					<td width="100"><b>Teachers NIC Number</b></td>
					<td width="130"><b>From Date</b></td>
					<td width="130"><b>Last_Updated_Date</b></td>
					</tr>';
					while($row=mysql_fetch_array($result))
					{
						$Training_Id=$_SESSION['Training_Id'];
						$T_NIC_Number=$_SESSION['T_NIC_Number'];
						if($row['Training_Id']==$Training_Id&&$row['T_NIC_Number']==$T_NIC_Number)
						{
							echo '<tr bgcolor="#936">';
							echo '<td width="100">'.$row['Training_Id'].'</td>';
							echo '<td width="100">'. $row['Member_Id'].'</td>';
							echo '<td width="100">'.$row['T_NIC_Number'].'</td>';
							echo '<td width="100">'.$row['From_Date'].'</td>';
							echo '<td width="130">'.$row['Last_Updated_Date'].'</td>';
							echo '</tr>';
							unset($_SESSION['Training_Id']);
							unset($_SESSION['T_NIC_Number']);
						}
						else
						{
							echo '<tr bgcolor="#CCCCCC">';
							echo '<td width="100">'.$row['Training_Id'].'</td>';
							echo '<td width="100">'. $row['Member_Id'].'</td>';
							echo '<td width="100">'.$row['T_NIC_Number'].'</td>';
							echo '<td width="100">'.$row['From_Date'].'</td>';
							echo '<td width="130">'.$row['Last_Updated_Date'].'</td>';
							echo '</tr>';
						}
					}
					echo "</table>";
		}
	}
	unset($_SESSION['OK']);
  }
}
?>
</div>
</div>
</div>
</div>
<div id="sidebar">
<br/>
<div id="partners" class="boxed">
			<h2 class="title">RESOURCE TEAM</h2>
            </div>
<?php
include_once "menu.php";
?>
<?php
include_once "../footer.php";
?>
<?php
}
?>
</div>
</div>
</body>
</html>